// pages/report/pdf/pdf.js
const api=require('../../../utils/request')
Page({

  /**
   * 页面的初始数据
   */
  data: {
   pdf:'',
   filePath:"",
   isShow:false,
   shareModel:{
    title:'',
    path:'pages/test/test', 
    fromButton:'one', 
  }, 
  fileName:'',
  name:'',
  posterId:'',
  imageList:[],
  pageNum:1,
  pageSize: 5,
  fileId:'',
  showDialog: false,
  catchtouchmove: true,
  memberId:'',
  reportId:'',
  pdfPath:'',
  isPdf: false,
  showLogin: false,
  image:'',
  backType:''
   },
     //联系客服
  kf(){
    //
//    wx.openCustomerServiceChat({
//        extInfo: {url: 'https://work.weixin.qq.com/kfid/kfcdb659362f1afb3c0'},
//        corpId: 'wwbb8c2c0fafdbf12b',
//        success(res) {
//            console.log('resss',res)
//        }
//      })

wx.navigateTo({
    url: '/pages/vip/vip_recommend/vip_recommend',
  })
  },
  //显示菜单
  showMenu(){
    this.setData({
      isShow:true
    });
  },
  switch(){
    this.setData({
      catchtouchmove:!this.data.catchtouchmove
    })
  },

  //隐藏菜单
  hideMenu(){
    this.setData({
      isShow:false
    });
  },
  onBackPress: function(options){ 
    return true
  },
 
 
 

 login(){
     wx.navigateTo({
        url: '/pages/login/login?type=3&id='+this.data.reportId+'&backType='+this.data.backType,
      })
 },
 // 查看pdf事件方法  
 pdf_open(id) {

//   wx.showLoading({
//       title: '加载中',
//   })
  let that=this
   
  
  api.get('weChatMini/findReportById/'+id).then(response=>{ 
      if(response.code===200){ 
          that.setData({
              image: response.data.image,
              fileName:response.data.name
          })
          wx.setNavigationBarTitle({
            title: response.data.name
        })

      }
    
  })
  // 下载文件方法
  
},
 
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let userInfo= wx.getStorageSync('user')
    if(userInfo!==''){
        wx.navigateBack({
            delta: 1 
        });
     }else{
        this.setData({
            reportId: options.id,
            backType: options.backType
         })
         this.pdf_open(options.id)
          
     }
    
   
  },
   
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
   // this.pdf_open();
     
    },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
        pdf: ''
    })
    let pdf=wx.getStorageSync('pdf')  
    this.setData({
        pdf: pdf
    })
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },
  handleReturn: function(e){
   },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
     if(this.data.backType===1){
        wx.switchTab({
            url: '/pages/report/report'
          })
    }else if(this.data.backType===2) {
        wx.navigateTo({
            url: '/pages/datas/datas',
          })
        
    }else if(this.data.backType===3){
      
          wx.navigateTo({
            url: '/pages/subject/subject',
          })
    }
     
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
   
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(res) {
    if(res.from==='button'){
        this.setData({
            FX: false
        })
     
    }
    return {
        title: this.data.name,
        path:'/pages/report/pdf/pdf?id='+this.data.posterId,
        imageUrl: this.data.image
      }
  },
  onShareTimeline(res){
    return {
        title: '',
        imageUrl: this.data.image,
        query:{}
    }

  },
   
})